
import 'dart:io';

import 'package:path_provider/path_provider.dart';
import 'package:flutter_book/util/extensions/string_extensions.dart';

class AppConfig{

  static var UA_NAME = "User-Agent";

  //版本号
  //在App启动时需要被重新赋值
  static String version = "0.0.1";
  static String buildNumber = "1";

  static String backstageApiUrl = "http://192.168.0.110:8080/";

  //app的文件根目录
  static String _appDir = "";

  //创建app用到的路径
  static void createAppDir() async {
    Directory extDir = await getApplicationDocumentsDirectory();
    _appDir = "${extDir.path}/pleasure_read_book";
    _appDir.print;

    await Directory(_appDir).create(recursive: true);
    await Directory(getAppPicDir()).create(recursive: true);
    await Directory(getAppVideoDir()).create(recursive: true);
    await Directory(getAppVoiceDir()).create(recursive: true);
    await Directory(getAppDownloadDir()).create(recursive: true);
    await Directory(getAppCourseDir()).create(recursive: true);
    await Directory(getAppPublishDir()).create(recursive: true);
    await Directory(getAppBookDir()).create(recursive: true);
  }

  //获取图片文件的路径
  static String getAppPicDir() {
    return "$_appDir/pic";
  }

  //获取视频文件的路径
  static String getAppVideoDir() {
    return "$_appDir/video";
  }

  //获取语音文件的路径
  static String getAppVoiceDir() {
    return "$_appDir/voice";
  }

  static String getAppVoiceFilePath() {
    return "${getAppVoiceDir()}/record_${new DateTime.now().millisecondsSinceEpoch}.aac";
  }

  //获取内部下载文件的路径
  static String getAppDownloadDir() {
    return "$_appDir/download";
  }

  //获取课程文件的路径
  static String getAppCourseDir() {
    return "$_appDir/course";
  }

  //获取发布文件的路径
  static String getAppPublishDir() {
    return "$_appDir/publish";
  }

  //获取存书籍book的路径
  static String getAppBookDir() {
    return "$_appDir/book";
  }
}